package com.xbongbong.paas.lowcode.impl;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.factory.LowCodeHandlerFieldFactory;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.abstracts.AbstractLowCodeHandlerFieldService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.lowcodeexecute.pojo.LowCodeExecuteServicePojo;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * @author 吴峰
 * @date 2021/03/18 15:08
 */
@Service("lowCodeHandlerDefaultFieldServiceImpl")
public class LowCodeHandlerDefaultFieldServiceImpl extends AbstractLowCodeHandlerFieldService {

    @PostConstruct
    public void register() {
        LowCodeHandlerFieldFactory.LOW_CODE_HANDLER_FIELD.put(FieldTypeEnum.TEXT.getType(), this);
        LowCodeHandlerFieldFactory.LOW_CODE_HANDLER_FIELD.put(FieldTypeEnum.TEXTAREA.getType(), this);
        LowCodeHandlerFieldFactory.LOW_CODE_HANDLER_FIELD.put(FieldTypeEnum.NUM.getType(), this);
        LowCodeHandlerFieldFactory.LOW_CODE_HANDLER_FIELD.put(FieldTypeEnum.DATETIME.getType(), this);
    }

    @Override
    public Object handlerField(FieldAttrEntity fieldAttrEntity, JSONObject data, LowCodeExecuteServicePojo lowCodeExecuteServicePojo) throws XbbException {
        return data.get(fieldAttrEntity.getAttr());
    }
}
